<?php defined('SYSPATH') OR die('No direct access allowed.');

class Collection_Model extends ORM{
	
	protected $has_one=array('contentmodule');
	protected $has_many=array('content','contcategory');
	protected $sorting = array('title' => 'asc');
	
	public function get_catcontainer_array(){
		if(trim($this->cat_containers)==""){
		return array();
		}
		$catcontarray=explode(',',$this->cat_containers);
		$retarray=array();
		foreach($catcontarray as $cat){
			$retarray[]=trim($cat);
		}
		return $retarray;
	}
	
	public function get_prev_next_id_new($startid=NULL, $contents=NULL){
		$all=$contents;
		$count=0;
		$chosenind=0;
		foreach($all as $elm){
			if($elm->id==$startid){
				$chosenind=$count;
				break;
			}	
			$count++;
		}
		$nextindex=$chosenind+1;
		$previndex=$chosenind-1;
		
		$nextid='';
		$previd='';
		if($nextindex<count($all)){
			$nextid=$all[$nextindex]->shortname;
		}
		if($previndex>=0){
			$previd=$all[$previndex]->shortname;
		}
	
	return array($previd, $nextid);
	}


	public function get_prev_next_id($startid=NULL){
		
		$all=$this->orderby('title')->content->as_array();
		
		$count=0;
		$chosenind=0;
		
		foreach($all as $elm){
			if($elm->id==$startid){
				$chosenind=$count;
				break;
			}	
			$count++;
		}
		$nextindex=$chosenind+1;
		$previndex=$chosenind-1;
		
		$nextid='';
		$previd='';
		if($nextindex<count($all)){
			$nextid=$all[$nextindex]->id;
		}
		if($previndex>=0){
			$previd=$all[$previndex]->id;
		}
	
	return array($previd, $nextid);
	}
	

}


